Skip to content

Avoid logging the DC API key value - #713

Open
carlosinfantes wants to merge 1 commit into
datacommonsorg:masterfrom
carlosinfantes:avoid-logging-api-key-value
Open

Avoid logging the DC API key value#713
carlosinfantes wants to merge 1 commit into
datacommonsorg:masterfrom
carlosinfantes:avoid-logging-api-key-value

Conversation

@carlosinfantes

Copy link
Copy Markdown

What

simple/util/dc_client.py logs the value of the Data Commons API key:

if _DEBUG:
  logging.info("DC API Root: %s", get_api_root())
  logging.info("DC API Key: %s", get_api_key())   # <-- logs the credential itself

This change logs whether the key is set rather than what it is, keeping the
diagnostic signal without writing the credential to the log sink.

Why it matters beyond local debugging

_DEBUG is hardcoded to True (line 38), not driven by an environment variable, so
this runs on every invocation in every deployment — not only when someone is debugging
locally.

In a Cloud Run deployment the line lands in Cloud Logging, where it is readable by
anyone with roles/logging.viewer on the project. That is a much broader audience than
the principals granted roles/secretmanager.secretAccessor on the secret the key is
mounted from, so the key effectively escapes the access model it was set up with. Log
sinks and exports widen it further.

We hit this on a Data Commons Platform deployment: the key appears in full in the
preprocessing job logs on every ingestion run.

Note on disclosure

We would have raised this privately, but this repository has no SECURITY.md and
private vulnerability reporting is not enabled, so there was no non-public channel to
use. Opening a separate issue to suggest adding one.

@google-cla

google-cla Bot commented Aug 5, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates simple/util/dc_client.py to prevent logging the actual DC API key when debugging is enabled, replacing it with a placeholder indicating whether the key is set or not. There are no review comments, so I have no feedback to provide.

@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity

Metric Results
Complexity 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

The debug block logs the key itself, so the credential ends up in plain text in
whatever log sink the deployment uses. On Cloud Run that means Cloud Logging,
where it is readable by anyone holding roles/logging.viewer on the project —
a considerably wider audience than those granted access to the secret.

_DEBUG is hardcoded to True, so this happens on every run of the preprocessing
job in any deployment, not just when debugging locally.

Log whether the key is set instead of its value, which keeps the diagnostic
signal (is it configured?) without disclosing the credential.
@carlosinfantes
carlosinfantes force-pushed the avoid-logging-api-key-value branch from d7547f3 to 525fdf3 Compare August 5, 2026 16:08
@gmechali
gmechali requested review from dwnoble and gmechali August 5, 2026 19:43

@gmechali gmechali left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you for this contribution. We absolutely should be redacting these keys.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants